# 作者: 菅世博
# 2025年02月19日10时32分14秒
# 512326042@qq.com

def use_set():
    # 集合的操作
    my_set = set() # 创建一个空集合
    print(my_set)
    print(type(my_set))

    my_set = {'apple', 'banana', 'orange'}
    print('apple' in my_set)  # 判断元素是否在集合中

def use_copy():
    # 集合的拷贝
    my_set = {'apple', 'banana', 'orange'}
    my_set2 = my_set.copy()
    print(f'id(my_set) = {id(my_set)} id(my_set2) = {id(my_set2)}')
    print(my_set2)

    # my_set[0] = 'pear' # TypeError: 'set' object does not support item assignment
    my_set3 = my_set
    print(my_set3)


def use_set_sym():
    """
    集合的快捷操作
    :return:
    """
    a = set('abracadabra')
    b = set('alprazolam')
    print(a, b)
    print(a - b)  # a和b的差集
    print(a | b)  # a和b的并集
    print(a & b)  # a和b的交集
    print(a ^ b)  # a和b中不同时存在的元素

    print(a - b == a.difference(b)) # a和b的差集等价运算


# use_set_sym()
use_copy()
# use_set()